package controller;
import model.*;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 管理员登录;
 * Created by yvdedu.com on 2016/9/26.
 */
@WebServlet(urlPatterns = "/register_manage")
public class register_manage extends HttpServlet{
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setCharacterEncoding("utf-8");
        String name=req.getParameter("name");
        String pwd=req.getParameter("pwd");
        if(name!=null&&pwd!=null){
            MySql mySql=new MySql();
            Manage manage=mySql.getManageByName(name);
            if(manage==null){
                Boolean result=mySql.addManage(name,pwd);
                if(result){
                    resp.getWriter().print("恭喜你，注册成功！");
                }else{
                    resp.getWriter().print("对不起，注册失败，请重试！");
                }
            }else{
                resp.getWriter().print("用户名已被注册，请更换重试！");
            }
        }else{
            resp.getWriter().print("用户名或密码不能为空！");
        }
    }
}
